package com.zui.manager;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.zui.security.User;


/**
 * 实现Acegi的UserDetailsService接口,获取用户Detail信息.
 * 
 * @author calvin
 */
public class UserDetailServiceImpl implements UserDetailsService {

	private UserManager userManager;
	@Required
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
		User user = (User) userManager.getUserByLoginName(userName);
		if (user == null)
			throw new UsernameNotFoundException(userName + "is not found!");

		return user;
	}

}
